﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace HYSoft.Web
{
    public partial class bianpo_edit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["uid"] == null || Session["uid"] == "")
            {
                Context.Response.Write("<script language=\"javascript\" type=\"text/javascript\">");
                Context.Response.Write("alert('对不起,你登录时间超时,请重新登录');top.location.href=\"index.html\";");
                Context.Response.Write("</script>");
                Context.Response.End();
            }
            if (!IsPostBack)
            {
                string type = Session["Usertype"] == null ? string.Empty : (string)Session["Usertype"];
                if (type != "单位用户")
                {
                    Response.Write("<script>alert('对不起，您没有更改边坡信息的权限！');history.go(-1);</script>");

                }
                InitData();
            }
        }
        /// <summary>
        /// 初始化信息，将某个边坡的信息进行显示在页面上（绑定）
        /// </summary>
        private void InitData()
        {
            bpbhvalue.Value = Request.QueryString["id"];
            string sql = " ljbp_sec_id=" + bpbhvalue.Value + "";
            DataSet ds = new BLL.bpinfo().GetList(sql);
            DataRow row = ds.Tables[0].Rows[0];
            lxmc.Value = row["route_name"].ToString().TrimStart().TrimEnd();
            bpgd.Value = row["slop_constr_site"].ToString().TrimStart().TrimEnd();
            pmwz.Value = row["sec_location"].ToString().TrimStart().TrimEnd();
            bpgaodu.Value = row["bpgd"].ToString().TrimStart().TrimEnd();
            bppd.Value = row["bppd"].ToString().TrimStart().TrimEnd();
            ljhdmxs.Value = row["ljhdmxs"].ToString().TrimStart().TrimEnd();
            ljlx.Value = row["ljlx"].ToString().TrimStart().TrimEnd();
            ljkd.Value = row["ljkd"].ToString().TrimStart().TrimEnd();
            ljdzlx.Value = row["ljdzlx"].ToString().TrimStart().TrimEnd();
            ljfhgclx.Value = row["ljfhgclx"].ToString().TrimStart().TrimEnd();
            ljfhgccl.Value = row["ljfhgccl"].ToString().TrimStart().TrimEnd();
            sql = " [index]=" + bpbhvalue.Value + "";
            DataSet ds1 = new BLL.monitor().GetList(sql);
            row = ds1.Tables[0].Rows[0];
            bpbh.Value = row["m_area_name"].ToString().TrimStart().TrimEnd() + "_" + row["addr"].ToString().TrimStart().TrimEnd();

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (this.IsValid)
            {
                string sql = " ljbp_sec_id=" + bpbhvalue.Value + "";
                DataSet ds = new BLL.bpinfo().GetList(sql);
                Model.bpinfo bpinfo = new BLL.bpinfo().GetModel(int.Parse(ds.Tables[0].Rows[0]["bpid"].ToString()));
                bpinfo.route_name = lxmc.Value.TrimStart().TrimEnd();
                bpinfo.slop_constr_site = bpgd.Value.TrimStart().TrimEnd();
                bpinfo.sec_location = pmwz.Value.TrimStart().TrimEnd();
                bpinfo.bpgd = int.Parse(bpgaodu.Value.TrimStart().TrimEnd());
                bpinfo.bppd = int.Parse(bppd.Value.TrimStart().TrimEnd());
                bpinfo.ljhdmxs = ljhdmxs.Value.TrimStart().TrimEnd();
                bpinfo.ljlx = ljlx.Value.TrimStart().TrimEnd();
                bpinfo.ljkd = int.Parse(ljkd.Value.TrimStart().TrimEnd());
                bpinfo.ljdzlx = ljdzlx.Value.TrimStart().TrimEnd();
                bpinfo.ljfhgclx = ljfhgclx.Value.TrimStart().TrimEnd();
                bpinfo.ljfhgccl = ljfhgccl.Value.TrimStart().TrimEnd();

                bool resultmessage = new BLL.bpinfo().Update(bpinfo);

                if (resultmessage == true)
                {
                    Response.Write("<script>if (confirm('边坡信息更新成功')) {"
                    + "  self.location = 'bianpo_manage.aspx';}</script>");
                    //   Response.Redirect("bianpo_manage.aspx");
                }
            }
        }
    }
}